package com.lzh.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzh.mapper.StudentMapper;
import com.lzh.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author reborn
 * @create 2020/5/22-14:44
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentMapper studentMapper;


    @Override
    public PageInfo<Student> selectStus(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> students = studentMapper.selectStus();
        PageInfo<Student> studentPageInfo = new PageInfo<>(students);
        return studentPageInfo;
    }

    @Override
    public Student selectStuById(int id) {
        return studentMapper.selectStuById(id);
    }


    @Override
    public PageInfo<Student> selectStuAll(Integer pageNum, Integer pageSize, List<Integer> ids) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> students =  studentMapper.selectStuAll(ids);
        PageInfo<Student> studentPageInfo = new PageInfo<>(students);
        return studentPageInfo;
    }



    @Override
    public int insertStu(Student student) {
        return studentMapper.insertStu(student);
    }

    @Override
    public int deleteStu(int id) {
        return studentMapper.deleteStu(id);
    }

    @Override
    public int updateStu(Student student) {
        return studentMapper.updateStu(student);
    }

    @Override
    public PageInfo<Student> selectStuByName(Integer pageNum, Integer pageSize,String name) {
        PageHelper.startPage(pageNum,pageSize);
        List<Student> students = studentMapper.selectStuByName(name);
        PageInfo pageInfo=new PageInfo<>(students);
        return pageInfo;
    }
}
